export default function (req, res) {
    const { body } = req;
    const { filters = {}, start = 1, limit = 10 } = body;
  
    const totalItems = 80; // Fixed total for consistent pagination mock
    const startIndex = (start - 1) * limit;
  
    // Define data sets for mock generation
    const orderTypes = [1, 2]; // 1-体验订单, 2-充值订单
    const refundStatuses = [1, 2, 3]; // 1-退费中, 2-退费成功, 3-退费失败
    const refundTypes = [1, 2]; // 1-全部退费, 2-部分退费
    const payTypes = [1, 2, 3, 4]; // 1-交付课时, 2-外部支付, 3-智牛币支付, 4-在线支付
    const paySubTypes = [1, 2, 3, 4, 5]; // 1-自有渠道, ..., 5-其他
    const reasonTypes = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13];
    const grades = ["一年级", "二年级", "三年级", "四年级", "五年级", "六年级", "初一", "初二", "初三", "初四", "高一", "高二", "高三", "大一", "大二", "大三", "大四", "大四以上"];
    const operators = [{ id: 101, name: "王操作" }, { id: 102, name: "赵操作" }];
  
    const generateMockRefund = (index) => {
      const refundId = 90000 + index;
      const orderType = orderTypes[Math.floor(Math.random() * orderTypes.length)];
      const refundStatus = refundStatuses[Math.floor(Math.random() * refundStatuses.length)];
      const refundType = refundTypes[Math.floor(Math.random() * refundTypes.length)];
      const studentPaidAmount = parseFloat((Math.random() * 2000 + 100).toFixed(2));
      const totalClasstime = parseFloat((Math.random() * 100 + 10).toFixed(1));
      const refundAmount = parseFloat((Math.random() * studentPaidAmount).toFixed(2));
      const refundClasstime = parseFloat((Math.random() * totalClasstime).toFixed(1));
  
      // Use a fixed format for dates to match the API spec
      const formatDate = (date) => {
        const year = date.getFullYear();
        const month = String(date.getMonth() + 1).padStart(2, '0');
        const day = String(date.getDate()).padStart(2, '0');
        const hours = String(date.getHours()).padStart(2, '0');
        const minutes = String(date.getMinutes()).padStart(2, '0');
        const seconds = String(date.getSeconds()).padStart(2, '0');
        return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
      };
  
      const createTime = new Date(Date.now() - Math.floor(Math.random() * 90) * 24 * 60 * 60 * 1000);
      const refundArrivalTime = refundStatus === 2 ? new Date(createTime.getTime() + Math.floor(Math.random() * 5) * 24 * 60 * 60 * 1000) : null;
  
      return {
        id: refundId,
        student: {
          id: Math.floor(Math.random() * 10000) + 1,
          name: `学员${Math.floor(Math.random() * 100) + 1}`,
          sn: `SN${Math.floor(Math.random() * 9000) + 1000}`,
          grade: grades[Math.floor(Math.random() * grades.length)],
          school: `模拟学校${Math.floor(Math.random() * 5) + 1}`,
          trainAccount: Math.random() < 0.5,
        },
        createTime: formatDate(createTime),
        refundNo: `REF${Math.floor(Math.random() * 90000000) + 10000000}`,
        orderType: orderType,
        refundStatus: refundStatus,
        refundType: refundType,
        orderNo: `ORD${Math.floor(Math.random() * 90000000) + 10000000}`,
        studentPaidAmount: studentPaidAmount,
        totalClasstime: totalClasstime,
        payType: payTypes[Math.floor(Math.random() * payTypes.length)],
        paySubType: paySubTypes[Math.floor(Math.random() * paySubTypes.length)],
        refundClasstime: refundClasstime,
        refundAmount: refundAmount,
        refundArrivalTime: refundArrivalTime ? formatDate(refundArrivalTime) : null,
        reasonTypes: [reasonTypes[Math.floor(Math.random() * reasonTypes.length)]],
        reason: `退费备注 ${Math.random().toString(36).substring(7)}`,
        signer: { id: Math.floor(Math.random() * 100) + 1, name: `签约人${Math.floor(Math.random() * 10) + 1}` },
        operator: operators[Math.floor(Math.random() * operators.length)],
      };
    };
  
    const mockDataList = Array.from({ length: totalItems }, (_, i) => generateMockRefund(i));
    
    // Implement filtering logic based on the request body
    const filteredList = mockDataList.filter(refund => {
      // Filter by student keyword/id
    //   if (filters.student && filters.student.keyword && !(refund.student.name.includes(filters.student.keyword) || refund.student.sn.includes(filters.student.keyword))) {
    //     return false;
    //   }
    //   // Filter by order ID
    //   if (filters.orderId && refund.orderId !== filters.orderId) {
    //     return false;
    //   }
    //   // Filter by order type
    //   if (filters.orderType && refund.orderType !== filters.orderType) {
    //     return false;
    //   }
    //   // Filter by refund status
    //   if (filters.refundStatus && refund.refundStatus !== filters.refundStatus) {
    //     return false;
    //   }
    //   // Filter by refund type
    //   if (filters.refundType && refund.refundType !== filters.refundType) {
    //     return false;
    //   }
    //   // Filter by order number
    //   if (filters.orderNo && refund.orderNo !== filters.orderNo) {
    //     return false;
    //   }
    //   // Filter by refund number
    //   if (filters.refundNo && !refund.refundNo.includes(filters.refundNo)) {
    //     return false;
    //   }
    //   // Filter by creation time range
    //   if (filters.createTimeMin && new Date(refund.createTime) < new Date(filters.createTimeMin)) {
    //     return false;
    //   }
    //   if (filters.createTimeMax && new Date(refund.createTime) > new Date(filters.createTimeMax)) {
    //     return false;
    //   }
      return true;
    });
  
    // Apply pagination to the filtered list
    const paginatedList = filteredList.slice(startIndex, startIndex + limit);
  
    return new Promise((resolve) => {
      setTimeout(() => {
        resolve({
          code: 0,
          message: '成功！',
          data: {
            current: start,
            size: limit,
            total: filteredList.length,
            list: paginatedList,
            summary: {}, // Placeholder for summary
          },
          timestamp: Date.now(),
          requestId: 'requestId_' + Math.random().toString(36).substring(2, 15),
          signature: 'signature_' + Math.random().toString(36).substring(2, 15),
        });
      }, 100);
    });
  }